package tds.model21;

import java.util.ArrayList;
import java.util.List;

/**
 * @Company 杭州先锋电子技术股份有限公司
 * @ClassName MyAggregate
 * @Description TODO（这里用一句话描述这个类的作用)
 * @author tds
 * @Date 2020/2/5 20:00
 * @version 1.0.0
 */
public class MyAggregate {

    private List<Object> list = new ArrayList<>();

    public void addObject(Object obj){
        list.add(obj);
    }

    public void removeObject(Object obj){
        list.remove(obj);
    }

    public MyIterator createIterator(){
        return new ConcrateIterator();
    }

    class ConcrateIterator implements MyIterator{

        private int cursor;

        @Override
        public Object getCurrentObj() {
            return list.get(cursor);
        }

        @Override
        public boolean hasNext() {
            return cursor < list.size();
        }

        @Override
        public void next() {
            if(cursor < list.size()){
                cursor++;
            }
        }

        @Override
        public boolean isFirst() {
            return cursor == 0;
        }
    }
}
